<?php
/**
 * 专享价数据处理
 * User: yumao
 * Date: 2018/3/9
 */
namespace app\controllers\crontab;
use app\components\redis\RedisLock;
use app\components\redis\RedisMarketingEmail;
use app\models\marketing\EmailCrm;
use app\models\marketing\GoodsDataPremium;
use Ares333\Curl\Toolkit;
use GuzzleHttp\Client;
use app\components\mq\MqComponent;
use app\components\PremiumPrice;
use app\models\marketing\BatchInfo;
use app\models\marketing\Region;
use app\models\marketing\MailTemplate;
use app\models\marketing\GoodsDataAuto;
use app\models\Elog;
use yii;
class PremiumPriceDataDealController extends \app\base\Controller
{    
    private $oneTimeCount = 5000; // 每次处理的条数
    private $config;
    private $startTime;
    private $siteCode; // 保存简码信息
    private $creatorId; // 创建人id
    private $creatorName; // 创建人名称
    private $sysLabelId; // 系统标签
    private $templateId; // 价格模板id
    public function init()
    {
        $this->config['maxDealTime'] = 120; // 最大处理时间
        $this->config['oneTimeGetNum'] = 36; // 每次获取网站端商品的数量
        $this->config['oneTimeDealGroup'] = 500; // 每次处理的组数 
        
        $this->config['oneTimeSendNum'] = 1; // 每次往网站端推送商品的数量 （现在接口只支持一条一条推送）
        // 发送的简码
        $this->siteCode = [
            "gearbest" => 'GB',
        ];
        //$this->config['oneTimeProgressNums'] = 20; // 并发获取数据的进程数
        // $this->config[''];
        $this->startTime = time(); // 开始时间
        // $this->creatorId = 0; // 创建人id
        $this->creatorId = 66; // 创建人id
        // $this->creatorName = "system_user_edm"; // 创建人名称
        $this->creatorName = "EMP"; // 创建人名称
        $this->sysLabelId = "1"; // 系统标签
        // $this->templateId = 46; // 价格模板id
        $this->templateId = 26; // 价格模板id
    }
    
    /**
     * yumao
     * 2018-3-13
     * 验证过滤
     */
    private function actionVerify($site)
    {
        if (empty($site)) {
            echo '必须传递网站名';
            exit;
        }
         // 判断当前网站是否存在
        $siteInfo = Yii::$app->params['sites']['marketing_email']['web_config'][$site];
        
        if (empty($siteInfo)) {
            echo '当前网站不存在';
            exit;
        }
    }
 
    /**
     * yumao
     * 2018-3-15
     * 从网站端获取密文（cookie_code）值
     */
    public function actionGetCookieCode()
    {
        set_time_limit(0);
        $mothod = strtolower(Yii::$app->request->getMethod());
        $site = Yii::$app->request->$mothod('site');
        $this->actionVerify($site);
        
        // 获取没有获取密文信息的批次数据
        $batchInfo = new BatchInfo();
        $batchCount = $batchInfo->getBatchNotCookieCodeCount($site);
        
        if (!empty($batchCount)) {
            $premiumPrice = new PremiumPrice();
            for ($i=0;$i<$batchCount;$i++) {
                try {
                    $cookieCode = $premiumPrice->getCookieCode($site);
                    if ($cookieCode) { // 更改批次信息表中的cookie
                        $batchInfo->setCookieCode($site,$cookieCode);                        
                    } else {
                        throw new \Exception("返回cookie为null");
                    }
                    
                } catch (\Exception $ex) {
                    $msg = "actionGetCookieCode，{$site}获取cookie_code失败.具体错误信息为:" . $ex->getMessage();
                    echo $msg;
                    Elog::logCrontab($msg, 'actionGetCookieCode','exception'); // 记录信息到elog
                }
            }
        } 
    }

    /**
     * yumao
     * 2018-3-15
     * 把有价格并且有相关专享价配置信息，
     * 但是没有添加到队列中并且没有发送专享价到SOA并且发送次数小于2的添加到mq中
     */
    public function actionPutPremiumGoodsToMq()
    {
        set_time_limit(0);
        $mothod = strtolower(Yii::$app->request->getMethod());
        $site = Yii::$app->request->$mothod('site');
        $this->actionVerify($site);
        //使用 Redis 锁，避免单个站点多个脚本去跑
        $redis = new RedisMarketingEmail();
        $redisLock = new RedisLock($redis, "put_premium_goods_to_mq_{$site}", 600);
        if ($redisLock->translock() === false) {
            return ;
        }
        
        $limit = $this->config['oneTimeSendNum'] * $this->config['oneTimeDealGroup']; // 每次查询的数量
        /** 查询相关数据并且进行处理start **/
        while (true){
            $goodsDataPremium = new GoodsDataPremium();
            $premiumGoodsInfo = $goodsDataPremium->getPremiumGoodsInfo($site, $limit);
            if(empty($premiumGoodsInfo)){
                break;
            }

            $regionIdArr = [];
            $templateIdArr = [];
            $regionInfoArr = [];
            $regionInfoDealArr = [];
            $templateInfoArr = [];
            $templateInfoDealArr = [];
            foreach ($premiumGoodsInfo as $premiumGoodsInfoVal) {
                if (!in_array($premiumGoodsInfoVal['regionId'], $regionIdArr)) {
                    $regionIdArr[] = $premiumGoodsInfoVal['regionId'];
                }
                if (!in_array($premiumGoodsInfoVal['templateId'], $templateIdArr)) {
                    $templateIdArr[] = $premiumGoodsInfoVal['templateId'];
                }
            }
            if ($regionIdArr) {
                $region = new Region();
                $regionInfoArr = $region->getRegionCodeByIdArr($regionIdArr);
                foreach ($regionInfoArr as $regionInfoArrVal) {
                    $regionInfoDealArr[$regionInfoArrVal['region_id']] = $regionInfoArrVal['region_code'];
                }
            }
            if ($templateIdArr) {
                $mailTemplate = new MailTemplate();
                $templateInfoArr = $mailTemplate->getTemplateByIdArr($templateIdArr);
                foreach ($templateInfoArr as $templateInfoArrVal) {
                    $templateInfoDealArr[$templateInfoArrVal['template_id']] = $templateInfoArrVal['template_name'];
                }

            }
//        foreach ($templateIdArr as $templateIdArrVal) {
//            $templateIdDealArr[$templateIdArrVal['templateId']]
//        }
//        echo '<pre>';
//        var_dump($premiumGoodsInfo);
//        exit;
            // 只处理批次号和渠道编码相同国家编码相同的配置信息id的数据,并且保存所有可用的数据的国家id值和批次id值
            if ($premiumGoodsInfo) {

                // 按照指定条数切分为组
                $premiumGoodsInfoChuck =  array_chunk($premiumGoodsInfo,$this->config['oneTimeSendNum']);
                foreach ($premiumGoodsInfoChuck as $premiumGoodsInfoChuckOne) {
                    $idArr = [];    // id记录
                    $bodyInfo = []; // 公共信息
                    $batchId =0;
                    $configId = 0;


                    foreach ($premiumGoodsInfoChuckOne as $key=>$premiumGoodsInfoOne) {
                        if (!$batchId) {
                            $batchId = $premiumGoodsInfoOne['batchId'];

                            $regionId = $premiumGoodsInfoOne['regionId'];

                            // 根据id获取国家编码
                            if (isset($regionInfoDealArr[$regionId])) {
                                $regionCode = $regionInfoDealArr[$regionId];
                            } else {
                                $regionCode = "";
                            }
//                        $regionInfo = $region->getRegionCodeById($regionId);
//                        $regionCode = !empty($regionInfo) ? $regionInfo['region_code'] : "";
                            // $premiumGoodsInfoChuckOne[$key]['regionCode'] = $regionCode['region_code'];

                            // 获取模板名称
//                        $templateInfo = $mailTemplate->getTemplateById($premiumGoodsInfoOne['templateId']);
//                        if ($templateInfo) {
//                            $templateName = $templateInfo['template_name'];
//                        } else {
//                            $templateName = "";
//                        }
                            if (isset($templateInfoDealArr[$premiumGoodsInfoOne['templateId']])) {
                                $templateName = $templateInfoDealArr[$premiumGoodsInfoOne['templateId']];
                            } else {
                                $templateName = "";
                            }
                            $configId = $premiumGoodsInfoOne['configId'];
                            // $pipelineCode = $premiumGoodsInfoOne['pipelineCode'];
                            $idArr[] = $premiumGoodsInfoOne['id'];

                            // 组装body信息
                            $bodyInfo['ciphertext'] = $premiumGoodsInfoOne['cookieCode']; // 密文

                            $bodyInfo['country'] = $regionCode; // 国家编码
                            $bodyInfo['creatorId'] = $this->creatorId; // 创建者id值
                            $bodyInfo['creatorName'] = $this->creatorName; // 创建者名称
                            $bodyInfo['validDays'] = $premiumGoodsInfoOne['validDays']; // 持续天数，用来计算结束时间
                            $goodsTemp = [];
                            $goodsTemp['goodSn'] = $premiumGoodsInfoOne['goodSn'];
                            $goodsTemp['shopCode'] = $premiumGoodsInfoOne['shopCode'];
                            $goodsTemp['id'] = $premiumGoodsInfoOne['id'];
                            $bodyInfo['goodSns'][] = $goodsTemp; // 商品sku信息
                            $bodyInfo['pipelineCode'] = $premiumGoodsInfoOne['pipelineCode']; // 渠道编码
                            $bodyInfo['price'] = number_format($premiumGoodsInfoOne['shop_price'] * $premiumGoodsInfoOne['priceDiscount'] / 10,2,".",""); // 专享价
                            $bodyInfo['priceName'] = $templateName;
                            $bodyInfo['siteCode'] = $premiumGoodsInfoOne['site_code']; // 站点编码
                            $bodyInfo['sponsor'] = $premiumGoodsInfoOne['sponsor']; // 平台主体
                            $bodyInfo['sysLabelId'] = $this->sysLabelId; // 系统标签
                            $bodyInfo['templateId'] = $this->templateId; // 模板ID
                            $bodyInfo['warehouseCode'] = $premiumGoodsInfoOne['warehouseCode']; // 仓库编码
                            // $bodyInfo['configId'] = $configId;

                        } else {
                            if($premiumGoodsInfoOne['batchId'] != $batchId || $premiumGoodsInfoOne['configId'] != $configId) {
                                unset($premiumGoodsInfoChuckOne[$key]);
                            } else {
                                // $premiumGoodsInfoChuckOne[$key]['regionCode'] = $regionCode['region_code'];
                                $idArr[] = $premiumGoodsInfoOne['id'];
                                $goodsTemp = [];
                                $goodsTemp['goodSn'] = $premiumGoodsInfoOne['goodSn'];
                                $goodsTemp['shopCode'] = $premiumGoodsInfoOne['shopCode'];
                                $goodsTemp['id'] = $premiumGoodsInfoOne['id'];
                                $bodyInfo['goodSns'][] = $goodsTemp;
                            }
                        }
                    }
                    $pushInRabbitData['body'] = $bodyInfo;
                    $pushInRabbitData['idArr'] = $idArr;
                    if (!empty($idArr)) {
                        try {
                            $trans = Yii::$app->db->beginTransaction();
                            $updateResult = $goodsDataPremium->changeGoodsData($site,$idArr,['is_in_rabbitmq_queue'=>1,'price_config_id'=>$configId]); // 把这一批数据的状态更改为已经加入到mq中
                            if (!empty($updateResult)) {
                                $returnFlag = MqComponent::sendMqData("send_{$site}_soa_goods_premium_price_EMP",json_encode($pushInRabbitData));
                                if ($returnFlag) {

                                    // mysql数据提交
                                    $trans->commit();
                                } else { // 说明加入到mq中失败了
                                    throw new \Exception("这一批数据加入mq中失败");
                                }
                            }
                        } catch (\Exception $ex) {
                            $trans->rollBack();
                            $msg = "actionPutPremiumGoodsToMq，{$site}商品专享价信息数据加入mq中失败.具体错误信息为:" . $ex->getMessage();
                            echo $msg;
                            Elog::logCrontab($msg, 'actionPutPremiumGoodsToMq','exception'); // 记录信息到elog
                        }
                    }

                }
            }
        }
        /** 查询相关数据并且进行处理end **/
        // 获取数据结束释放锁
        $redisLock->unlock();
        //全部加入到 MQ 之后，就可以调用脚本去消费这些数据了
        $toolkit = new Toolkit();
        $curl = $toolkit->getCurl();
        $curl->onInfo = null;
        $curl->add(
            [
                'opt'=>[
                    CURLOPT_URL=>Yii::$app->params['web_url'] . '/crontab/premium-price-data-deal/send-premium-price-multi-threads?module_name=marketing_email&site='.$site
                ]
            ]
        );
        $curl->start();
    }
    
    /**
     * yumao
     * 2018-3-14
     * 把数据未处理的获取商品价格数据加入mq中一组
     */
    public function actionPutGoodsToMq()
    {
        set_time_limit(0);
        $mothod = strtolower(Yii::$app->request->getMethod());
        $site = Yii::$app->request->$mothod('site');
        $this->actionVerify($site);
        //使用 Redis 锁，避免单个站点多个脚本去跑
        $redis = new RedisMarketingEmail();
        $redisLock = new RedisLock($redis, "put_goods_to_mq_{$site}", 600);
        if ($redisLock->translock() === false) {
            return ;
        }
        $limit = $this->config['oneTimeGetNum'] * $this->config['oneTimeDealGroup'];
       // $trans = Yii::$app->db->beginTransaction();
        /*** 查询没有处理过的并且没有在对列中的相关数据加入mq中 start ***/
        while (true){
            $goodsDataPremium = new GoodsDataPremium();
            $goodsData = $goodsDataPremium->getGoodsInfo($site, $limit);
            //数据全部处理完了才跳出
            if(empty($goodsData)){
                break;
            }
            // 按照指定条数切分为组
            $goodsDataChuck =  array_chunk($goodsData,$this->config['oneTimeGetNum']);

            foreach ($goodsDataChuck as $goodsDataChuckOne) {
                $idArr = []; // 保存id值
                $goodsDataDeal = []; // 保存处理后的数据待加入到mq中的数据

                foreach ($goodsDataChuckOne as $goodsDataChunkOneVal) {
                    $idArr[] = $goodsDataChunkOneVal['id'];
                    unset($goodsDataChunkOneVal['id']);
                    $goodsDataDeal[] = $goodsDataChunkOneVal;
                }
                $pushInRabbitData['goodsDataDeal'] = $goodsDataDeal;
                $pushInRabbitData['idArr'] = $idArr;
                if (!empty($idArr)) {
                    try {
                        $trans = Yii::$app->db->beginTransaction();
                        $updateResult = $goodsDataPremium->changeInMqState($site,$idArr,1); // 把这一批数据的状态更改为已经加入到mq中

                        // 组装完整的数据
//                    $oneCompletionSendInfo['header'] = $this->header[$site];
//                    $oneCompletionSendInfo['body']['goodPriceReqs'] = $goodsDataDeal;
//                    $oneCompletionSendInfo['body']['siteCode'] = $this->siteCode[$site];
                        if (!empty($updateResult)) {
                            // $returnFlag = MqComponent::sendMqData("get_{$site}_soa_goods_price_EMP",json_encode($oneCompletionSendInfo));
                            $returnFlag = MqComponent::sendMqData("get_{$site}_soa_goods_price_EMP",json_encode($pushInRabbitData));
                            if ($returnFlag) {

                                // mysql数据提交
                                $trans->commit();
                            } else { // 说明加入到mq中失败了
                                // 改成抛异常 2-7
                                throw new \Exception("这一批数据加入mq中失败");
                            }
                        }
                    } catch (\Exception $ex) {
                        $trans->rollBack();
                        $msg = "actionPutGoodsToMq，{$site}商品信息数据加入mq中失败.具体错误信息为:" . $ex->getMessage();
                        echo $msg;
                        Elog::logCrontab($msg, 'actionPutGoodsToMq','exception'); // 记录信息到elog
                    }
                }
            }
        }
        /*** 查询没有处理过的并且没有在对列中的相关数据加入mq中 end ***/
        $redisLock->unlock();
        //全部加入到 MQ 之后，就可以调用脚本去消费这些数据了
        $toolkit = new Toolkit();
        $curl = $toolkit->getCurl();
        $curl->onInfo = null;
        $curl->add(
            [
                'opt'=>[
                    CURLOPT_URL=>Yii::$app->params['web_url'] . '/crontab/premium-price-data-deal/get-goods-shop-price-multi-threads?module_name=marketing_email&site='.$site
                ]
            ]
        );
        $curl->start();
    }
    
    /**
     * yumao
     * 2018-3-16
     * 从mq中取出商品信息消费，把专享价推送给网站
     */
    public function actionSendPremiumPrice()
    {
        set_time_limit(0);
        $mothod = strtolower(Yii::$app->request->getMethod());
        $site = Yii::$app->request->$mothod('site');
        $this->actionVerify($site);
        $premiumPrice = new PremiumPrice();
        MqComponent::receiveQueueData("send_{$site}_soa_goods_premium_price_EMP",$premiumPrice,'sendPremiumPrice');
    }

    /**
     * 使用多线程去调用 actionSendPremiumPrice 方法
     * @author chenshanwen
     * @date 2018-07-17
     */
    public function actionSendPremiumPriceMultiThreads()
    {
        set_time_limit(0);
        //加一个 redis 缓存键，避免停止不下来
        $redis = new RedisMarketingEmail();
        $stop = $redis->get('stop_send_premium_price');
        if($stop){
            return;
        }
        $mothod = strtolower(Yii::$app->request->getMethod());
        $site = Yii::$app->request->$mothod('site') ?: 'gearbest';
        $threads = Yii::$app->request->$mothod('threads') ?: 20;
        //采用 curl 的多线程同时请求多个
        $toolkit = new Toolkit();
        $curl = $toolkit->getCurl();
        $curl->onInfo = null;
        for ($i = 1;$i<= $threads;$i++){
            $curl->add(
                array(
                    'opt' => array(
                        CURLOPT_URL => Yii::$app->params['web_url'] . '/crontab/premium-price-data-deal/send-premium-price?module_name=marketing_email&site='.$site.'&i='.$i,
                    )
                )
            );
        }
        $curl->start();
    }
    
    /**
     * yumao
     * 2018-3-13
     * 从mq中取出商品信息数据消费，从网站端获取商品详情页面价格
     */
    public function actionGetGoodsShopPrice()
    {
        set_time_limit(0);
        $mothod = strtolower(Yii::$app->request->getMethod());
        $site = Yii::$app->request->$mothod('site');
        $this->actionVerify($site);
        //$obj
        $premiumPrice = new PremiumPrice();
        MqComponent::receiveQueueData("get_{$site}_soa_goods_price_EMP",$premiumPrice,'getGoodsShopPrice');
        //获取完了之后开始下一项工作
       $toolkit = new Toolkit();
       $curl = $toolkit->getCurl();
       $curl->onInfo = null;
       $curl->add(
           [
               'opt'=>[
                   CURLOPT_URL=>Yii::$app->params['web_url'] . '/crontab/premium-price-data-deal/put-premium-goods-to-mq?module_name=marketing_email&site='.$site,
               ]
           ]
       );
       $curl->start();
    }

    /**
     * @author chenshanwen
     * @date 2018-07-18
     * 采用多线程去请求 actionGetGoodsShopPrice() 这个方法
     */
    public function actionGetGoodsShopPriceMultiThreads()
    {
        set_time_limit(0);
        //加一个 redis 缓存键，避免停止不下来
        $redis = new RedisMarketingEmail();
        $stop = $redis->get('stop_get_goods_shop_price');
        if($stop){
            return;
        }
        $mothod = strtolower(Yii::$app->request->getMethod());
        $site = Yii::$app->request->$mothod('site') ?: 'gearbest';
        //默认用20个线程去跑，加快MQ消费速度
        $threads = Yii::$app->request->$mothod('threads') ?: 20;
        //采用 curl 的多线程同时请求多个
        $toolkit = new Toolkit();
        $curl = $toolkit->getCurl();
        $curl->onInfo = null;
        for ($i = 1;$i<= $threads;$i++){
            $curl->add(
                array(
                    'opt' => array(
                        CURLOPT_URL => Yii::$app->params['web_url'] . '/crontab/premium-price-data-deal/get-goods-shop-price?module_name=marketing_email&site='.$site.'&i='.$i,
                    )
                )
            );
        }
        $curl->start();
    }
    
    /**
     * yumao
     * 2018-3-20
     * 把整合处理完插入到user_{$site}_goods_data表中
     */
    public function actionAddCrmDataToGoodsData()
    {
        set_time_limit(0);
        $mothod = strtolower(Yii::$app->request->getMethod());
        $site = Yii::$app->request->$mothod('site');
        $this->actionVerify($site);
        $type = Yii::$app->request->$mothod('type');
        $typeArr = ['eocart','eoview_new'];
        if (!in_array($type,$typeArr)) {
            exit('type is error');
        }
        //使用 Redis 锁，避免单个站点多个脚本去跑
        $redis = new RedisMarketingEmail();
        $redisLock = new RedisLock($redis, "add_crm_data_to_goods_data_{$site}_{$type}", 600);
        if ($redisLock->translock() === false) {
            return ;
        }

        /*** 查询处理过（is_deal为1）但是state为0（未加入到user_{$site}_goods_data）的相关类型的数据并进行处理 start *****/
        $emailCrm = new EmailCrm();
        $oneTimeDeal = 500; // 每次处理500个用户数据
        while (true) {
            $userIdArr = $emailCrm->getOneBatchUser($site,$type,$oneTimeDeal);
            if(empty($userIdArr)){
                break;
            }
           
            $userIdArrDeal = [];
            foreach ($userIdArr as $userIdArrOne) {
                $userIdArrDeal[] = $userIdArrOne['user_id'];
            }
            $userGoodsInfo = $emailCrm->getUserGoodsInfoByUserId($site,$userIdArrDeal,$type); // 获取这一批用户数据
            if ($userGoodsInfo) {
                
                // 遍历数据把user_id相同的归于同一条数据
                $userGoodsInfoDeal = [];
                foreach ($userGoodsInfo as $userGoodsInfoVal) {
                    $userGoodsInfoVal['goods_link'] = addslashes($userGoodsInfoVal['goods_link']);
                    $userGoodsInfoVal['good_title'] = addslashes($userGoodsInfoVal['good_title']);
                    $userGoodsInfoVal['goods_picture'] = addslashes($userGoodsInfoVal['goods_picture']);
                    $userGoodsInfoDeal[$userGoodsInfoVal['user_id']][$userGoodsInfoVal['id']] = $userGoodsInfoVal;
                }
                
                 // 处理这一批user数据
                $trans = Yii::$app->db->beginTransaction(); // 开启事务
                try {
                    
                    // 数据入库到user_{$site}_goods_data表中
                    $goodsDataAuto = new GoodsDataAuto();
                    $goodsDataAuto->dealDataCrm($userGoodsInfoDeal,$site,$type); 
                    
                    // 更改crm推送表中相关数据状态
                    $emailCrm->updateUserGoodsInfoByUserId($site,$userIdArrDeal,$type);
                   
                    // mysql数据提交
                    $trans->commit();
                } catch (\Exception $ex) {
                    echo $ex->getMessage();
                    // mysql数据回滚
                    $trans->rollBack();         
                }
            }
            sleep(1); // 每处理一批数据则休眠1秒
        }
        
        /*** 查询当天处理过（is_deal为1）但是state为0（未加入到user_{$site}_goods_data）的相关类型的数据并进行处理 end *****/
        $redisLock->unlock();
    }
    
    /**
     * yumao
     * 2018-3-9
     * 处理crm的传送过来的相关商品数据(购物车)
     */
    public function actionDealCrmData()
    {
        set_time_limit(0);
        $actionTime = microtime(true);
        $mothod = strtolower(Yii::$app->request->getMethod());
        $site = Yii::$app->request->$mothod('site');
        $type = Yii::$app->request->$mothod('type');
        Elog::logCrontab("处理CRM推送过来的数据-{$type}-".$actionTime.'-BEGIN', 'actionDealCrmCartData','info');
        $this->actionVerify($site);
        $typeArr = ['eocart','eoview_new'];
        if (!in_array($type,$typeArr)) {
            exit('type is error');
        }
        // 增加或查询一条批次信息
        $batchModel = new BatchInfo();
        $batchId = $batchModel->addOrQueueBatch($site,$type);
        //获取没有处理过的数据，并处理
        $emailCrm = new EmailCrm();
        $emailCrm->getUndealDataAndDeal($site,$batchId,$type);
        Elog::logCrontab("处理CRM推送过来的数据-{$type}-".$actionTime.'-END，耗时：'.(microtime(true)-$actionTime)*1000, 'actionDealCrmCartData','info');
        //处理完了之后去获取 cookie
        $toolkit = new Toolkit();
        $curl = $toolkit->getCurl();
        $curl->onInfo = null;
        $curl->add(
            [
                'opt'=>[
                    CURLOPT_URL => Yii::$app->params['web_url'].'/crontab/premium-price-data-deal/get-cookie-code?module_name=marketing_email&site='.$site,
                ],
            ],
            //cookie 取成功之后把需要获取价格的商品丢到 MQ 里面去
            function($r) use ($curl,$site){
                $curl->add(
                    [
                        'opt'=>[
                            CURLOPT_URL=>Yii::$app->params['web_url'].'/crontab/premium-price-data-deal/put-goods-to-mq?module_name=marketing_email&site='.$site,
                        ]
                    ]
                );
            }
        );
        $curl->start();
    }

    /**
     * 处理rg订单信息
     * @author xianxuefeng
     * @date 20180726
     */
    public function actionGetRgOrder()
    {
        set_time_limit(0);
        $method = strtolower(Yii::$app->request->getMethod());
        Yii::$app->request->$method("site");
        $deal_site_name = Yii::$app->request->$method('deal_site_name');
        $this->actionVerify($deal_site_name);
        $premiumPrice = new PremiumPrice();
        MqComponent::receiveQueueData("orderInfo_EMP",$premiumPrice,'GetRgOrder');
        echo "\n\tdone...\n";
    }
}


//update
//
//
//统计
//筛选
